import { createApp } from "vue";
import { createPinia } from "pinia";
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
import App from "./App.vue";
import router from "./router";
import "element-plus/dist/index.css";
import "./assets/css/icon.css";
import BaiduMap from "vue-baidu-map-3x";
import eventBus from "./utils/event-bus.js";
const app = createApp(App);
app.use(createPinia());
app.use(router);
app.use(BaiduMap, {
  ak: "I5WQcH0V9tKHDknrAy0LEOLCie3DfcPX",
});
// 注册elementplus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}
// 自定义权限指令

// const permiss = usePermissStore();
// app.directive("permiss", {
//   mounted(el, binding) {
//     if (!permiss.key.includes(String(binding.value))) {
//       el["hidden"] = true;
//     }
//   },
// });

app.mount("#app");

const handleLogoutEvent = (payload: any) => {
  console.log("收到自定义事件:", payload);
  router.push("/login");
  localStorage.removeItem("token");
};
eventBus.on("logout-event", handleLogoutEvent);
